<?php require_once('Connections/mysql_admin.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['usuario'])) {
  $loginUsername=$_POST['usuario'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "gestor/index.php";
  $MM_redirectLoginFailed = "index.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_mysql_admin, $mysql_admin);
  
  $LoginRS__query=sprintf("SELECT usuario_normal, password_normal FROM registo_normal WHERE usuario_normal=%s AND password_normal=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $mysql_admin) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LSecurity</title>
<style type="text/css">
<!--
body {
	background-color: #3399FF;
}
-->
</style>
<style type="text/css">
<!--
.style2 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style5 {
	font-size: 12;
	color: #333333;
}
.style6 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9px;
	color: #006FDD;
}
-->
</style>
<style type="text/css">
<!--
.style8 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #005CB9;
}
-->
</style>
<script src="SpryAssets/SpryCollapsiblePanel.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style10 {
	font-size: 10px
}
.style11 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	text-decoration: underline overline;
}
.style12 {color: #333333}
.style13 {
	font-size: 12px;
	font-weight: bold;
}
-->
</style>
</head>

<body>
<div align="center">
  <p><img src="index.gif" width="400" height="150" /></p>
</div>
<table width="869" height="112" border="0" align="center">
  <tr>
    <td width="870"><form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
        <div align="center">        </div>
        <div align="center" class="style6">
          <div id="CollapsiblePanel1" class="CollapsiblePanel">
            <div class="CollapsiblePanelTab style10 style11" tabindex="0">Log-In no Servidor</div>
            <div class="CollapsiblePanelContent">
              <div align="center">
                <p class="style2 style12">Usuário: </p>
              </div>
              <span id="sprytextfield1">
              <label> </label>
              <div align="center"><span id="sprytextfield5">
                <input name="usuario" type="text" id="usuario" size="25" />
                <span class="textfieldRequiredMsg">Campo Obrigatorio!</span></span></div>
            </span> <br />
            <div align="center" class="style2"><span class="style5">Password:</span></div>
            <div align="center"></div>
            <label> <span id="sprytextfield"> </span> </label>
            <div align="center"><span id="sprytextfield6">
              <input name="password" type="password" id="password" size="26" />
              <span class="textfieldRequiredMsg">Campo Obrigatorio!</span></span></div>
            <label> <span id="sprytextfield"> </span> </label>
            <div align="center"><span id="sprytextfield"><br />
                  <input type="submit" name="entrar" id="entrar" value="Entrar" />
            </span></div>
            </div>
          </div>
        </div>
        <div align="center"></div>
    </form>    </td>
  </tr>
</table>
<p align="center" class="style8"><a href="login_admin.php" class="style13">Admin</a><br />
  <br />
Feito por Deluxor 2007</p>
<script type="text/javascript">
<!--
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel1", {contentIsOpen:false});
var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6");
var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5");
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4");
//-->
</script>
</body>
</html>
